package com.ruoyi.common.integrate.service;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

/**
 * @Author: MMDZ
 * @Desc: TODO 获取其他 数据库信息
 */
@Component
public class DBService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private CommonService commonService;

    /**
     * 同步U8数据-项目代码
     */
    public List<String> syncU8Data() {
        SqlSessionFactory sqlSessionFactory = null;
        SqlSession openSession = null;
        try {
            sqlSessionFactory = commonService.getSqlServerSessionFactory();
            openSession = sqlSessionFactory.openSession();
            // U8所有项目代码
            List<String> projectCodeList = openSession.selectList("ProjectForU8Mapper.selectProjectForU8");
            return projectCodeList;
        } catch (IOException e) {
            e.printStackTrace();
            logger.error("同步U8数据-项目代码 异常: ===》》》 " + e.getMessage());
        } finally {
            if (null != openSession) {
                openSession.close();
            }
        }
        return null;
    }

}
